package com.jz.yanshe.ui.widget;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;

import jz.com.feierman.R;



/**
 * Created by Administrator on 2018/1/9.
 */

public class CheckBoxText extends android.support.v7.widget.AppCompatTextView implements View.OnClickListener{

    public boolean isCheck = false;
    public OnGroup onGroup;
    public int goodsCategoryId;
    public int sortByType;
    public int descOrAsc;

    public CheckBoxText(Context context) {
        super(context);
        init();
    }

    public CheckBoxText(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public CheckBoxText(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init(){
        setBackgroundResource(R.drawable.item_bg_grey);
        setTextColor(Color.parseColor("#333333"));
        setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if(onGroup != null)
        {
            onGroup.onGroup();
        }

        if(isCheck){
            setBackgroundResource(R.drawable.item_bg_grey);
            setTextColor(Color.parseColor("#333333"));
        }else{
            setBackgroundResource(R.drawable.item_bg_red);
            setTextColor(Color.parseColor("#E61717"));
        }
        isCheck = !isCheck;

        if(onGroup != null)
        {
            onGroup.startDate();
        }
    }


    public interface OnGroup{
        void onGroup();
        void startDate();
    }
    public void clear(){
        setBackgroundResource(R.drawable.item_bg_grey);
        setTextColor(Color.parseColor("#333333"));
    }
}
